package com.dingding.dao.systemdao.impl;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.dingding.bean.entity.SystemKey;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.dao.basedao.impl.BaseDaoImpl;
import com.dingding.dao.systemdao.ISystemKeyDao;

/**
 * 
 * @ClassName: SystemKeyImpl 
 * @Description: 
 * @author cheshaowei
 * @date 2015-10-27 下午05:44:34
 * 
 */
public class SystemKeyDaoImpl extends BaseDaoImpl<SystemKey> implements ISystemKeyDao{
   
	
	/**
	 * @Title: getSystemKey 
	 * @Description:获取系统加密、解密秘钥
	 * @author cheshaowei
	 * @throws
	 */
	@Override
	public SystemKey getSystemKey(){
		
		// 添加查询条件
		Criterion criterion = Restrictions.eq("keyType", 1);
		// 获取秘钥bean
		SystemKey systemKey = super.queryCriteriaUnResult(
				criterion, false);
		
		return systemKey;
		
	}
	
	/**
	 * @Title: addSystemKey 
	 * @Description:初始化秘钥到数据库
	 * @author cheshaowei
	 * @throws
	 */
	@Override
    public void addSystemKey(SystemKey systemKeyParam){
    	
         SystemKey systemKey = new SystemKey();
         //秘钥主键ID
         systemKey.setSkId(ToolUtil.getUid());
    	 //秘钥类型 1：秘钥
         systemKey.setKeyType(1);
         //客户端公钥
         systemKey.setClientPublicKey(systemKeyParam.getClientPublicKey());
         //客户端私钥
         systemKey.setClientPrivateKey(systemKeyParam.getClientPrivateKey());
         //服务器公钥
         systemKey.setServerPublicKey(systemKeyParam.getServerPublicKey());
         //服务器私钥
         systemKey.setServerPrivateKey(systemKeyParam.getServerPrivateKey());
         
         super.save(systemKey);
    	
    }
	
}
